package net.huashitong.ssydt.provider.money.controller.ssMoneyGoldController;


import net.huashitong.ssydt.money.entity.vo.SsMoneyGoldRecordInVO;
import net.huashitong.ssydt.provider.money.controller.ClientUtils;
import net.huashitong.user.http.Result;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * @author hemj
 * @version 2017/8/21
 */
public class UpdateGoldNumber {

	private static final String VALID_USER_ID = "20170817100000000026";

	@Test
	public void successInc() {
		SsMoneyGoldRecordInVO ssMoneyGoldRecordInVO = new SsMoneyGoldRecordInVO();
		ssMoneyGoldRecordInVO.setUserId(VALID_USER_ID);
		ssMoneyGoldRecordInVO.setOperation("+");
		ssMoneyGoldRecordInVO.setGoldNumber(1000L);
		ssMoneyGoldRecordInVO.setDescription("后台充值");

		String url = TestUtils.getUrl(VALID_USER_ID);
		Result<String> result = ClientUtils.clientManager.putFormData(url, ssMoneyGoldRecordInVO);
		System.out.println(result);
		assertEquals(Result.Status.SUCCESS, result.getCode());
	}

	@Test
	public void successDec() {
		SsMoneyGoldRecordInVO ssMoneyGoldRecordInVO = new SsMoneyGoldRecordInVO();
		ssMoneyGoldRecordInVO.setUserId(VALID_USER_ID);
		ssMoneyGoldRecordInVO.setOperation("-");
		ssMoneyGoldRecordInVO.setGoldNumber(1000L);
		ssMoneyGoldRecordInVO.setDescription("后台充值");

		String url = TestUtils.getUrl(VALID_USER_ID);
		Result<String> result = ClientUtils.clientManager.putFormData(url, ssMoneyGoldRecordInVO);
		System.out.println(result);
		assertEquals(Result.Status.SUCCESS, result.getCode());
	}

	@Test
	public void validateFailure() {
		SsMoneyGoldRecordInVO ssMoneyGoldRecordInVO = new SsMoneyGoldRecordInVO();
		String url = TestUtils.getUrl(VALID_USER_ID);
		Result<String> result = ClientUtils.clientManager.putFormData(url, ssMoneyGoldRecordInVO);
		System.out.println(result);
		assertEquals(Result.Status.PARAM_ERROR, result.getCode());
	}

	@Test
	public void invalidUserId() {
		SsMoneyGoldRecordInVO ssMoneyGoldRecordInVO = new SsMoneyGoldRecordInVO();
		ssMoneyGoldRecordInVO.setUserId("123");
		ssMoneyGoldRecordInVO.setOperation("+");
		ssMoneyGoldRecordInVO.setGoldNumber(1000L);
		ssMoneyGoldRecordInVO.setDescription("后台充值");

		String url = TestUtils.getUrl("123");
		Result<String> result = ClientUtils.clientManager.putFormData(url, ssMoneyGoldRecordInVO);
		System.out.println(result);
		assertEquals(Result.Status.ERROR, result.getCode());
		assertEquals("用户的账户不存在", result.getMessage());
	}

	@Test
	public void invalidOperation() {
		SsMoneyGoldRecordInVO ssMoneyGoldRecordInVO = new SsMoneyGoldRecordInVO();
		ssMoneyGoldRecordInVO.setUserId(VALID_USER_ID);
		ssMoneyGoldRecordInVO.setOperation("*");
		ssMoneyGoldRecordInVO.setGoldNumber(1000L);
		ssMoneyGoldRecordInVO.setDescription("后台充值");

		String url = TestUtils.getUrl(VALID_USER_ID);
		Result<String> result = ClientUtils.clientManager.putFormData(url, ssMoneyGoldRecordInVO);
		System.out.println(result);
		assertEquals(Result.Status.ERROR, result.getCode());
		assertEquals("金币操作类型不正确", result.getMessage());
	}

	@Test
	public void invalidGoldNumber() {
		SsMoneyGoldRecordInVO ssMoneyGoldRecordInVO = new SsMoneyGoldRecordInVO();
		ssMoneyGoldRecordInVO.setUserId(VALID_USER_ID);
		ssMoneyGoldRecordInVO.setOperation("-");
		ssMoneyGoldRecordInVO.setGoldNumber(-1000L);
		ssMoneyGoldRecordInVO.setDescription("后台充值");

		String url = TestUtils.getUrl(VALID_USER_ID);
		Result<String> result = ClientUtils.clientManager.putFormData(url, ssMoneyGoldRecordInVO);
		System.out.println(result);
		assertEquals(Result.Status.PARAM_ERROR, result.getCode());
		assertEquals("金币不能为负数;", result.getMessage());
	}
}
